import 'package:website.core/core/infrastructure/dtos/api/api_web_one_time_purchase_item_dto.dart';
import 'package:website.core/core/infrastructure/dtos/api/api_web_purchase_item_dto.dart';
import 'package:website.core/core/infrastructure/dtos/api/api_web_subscription_dto.dart';

class ApiWebPurchaseItemDtoFactory {
  const ApiWebPurchaseItemDtoFactory._internal();

  static const _instance = ApiWebPurchaseItemDtoFactory._internal();

  factory ApiWebPurchaseItemDtoFactory() {
    return _instance;
  }

  ApiWebPurchaseItemDto fromJson(Map<String, dynamic> json) {
    final type = json[kApiWebPurchaseItemTypeKey] as String;

    if (type == kApiWebSubscriptionTypeValue) {
      return ApiWebSubscriptionDto.fromJson(json);
    }

    if (type == kApiWebOneTimePurchaseItemTypeValue) {
      return ApiWebOneTimePurchaseItemDto.fromJson(json);
    }

    throw UnimplementedError();
  }
}
